package yxy.game.pm2.active.command.limitexchange;

import yxy.cherry.game.base.message.MessageEmitterHandler;
import yxy.cherry.game.base.message.annotation.MessageSource;
import yxy.cherry.game.base.message.annotation.MessageType;
import yxy.game.pm2.Result;
import yxy.game.pm2.active.handle.Act_ConquestHandle;
import yxy.game.pm2.active.module.sdk.shengye.ShengYeSubscribeModule;
import yxy.game.pm2.command.Command;
import yxy.game.pm2.message.ActiveMessage;

/** 限时兑换征战 挂机奖励收取询问 */
@MessageType(proto = Command.ActLimitExchangeConquestIdleBonusAsk, classtype = ActiveMessage.ActLimitExchangeConquestIdleBonusAskRequest.class)
public class CMD_Active_限时兑换_ConquestIdleBonusAsk extends Command<ActiveMessage.ActLimitExchangeConquestIdleBonusAskRequest> {

	@Override
	public void execute(MessageSource messageSource, ActiveMessage.ActLimitExchangeConquestIdleBonusAskRequest request) {
		String playerCode = messageSource.getTag();

		
		Act_ConquestHandle conquestHandle = new Act_ConquestHandle();
//		ConquestHandle conquestHandle = new ConquestHandle();
		Result result = conquestHandle.idleBonusAsk(playerCode);
		if (result.equals(Result.ConquestRewardUpper)) {
			ActiveMessage.ActLimitExchangeConquestIdleBonusAskResponse.Builder response = ActiveMessage.ActLimitExchangeConquestIdleBonusAskResponse.newBuilder();
			send(messageSource, response, result);
			return;
		}

		ActiveMessage.ActLimitExchangeConquestIdleBonusResponse.Builder response = ActiveMessage.ActLimitExchangeConquestIdleBonusResponse.newBuilder();
		
		try {
			result = new Act_ConquestHandle().idleBonus_Act限时兑换(playerCode, response);
			send(messageSource, response, result);
			
			if(result.getNumber() == Result.Success.getNumber()) {
				ShengYeSubscribeModule.updatenexttimes(playerCode);				
			}
		} catch (Exception e) {
			send(messageSource, response, Result.DataError);
		}

	}

	private void send(MessageSource messageSource, ActiveMessage.ActLimitExchangeConquestIdleBonusAskResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}

	private void send(MessageSource messageSource, ActiveMessage.ActLimitExchangeConquestIdleBonusResponse.Builder response, Result result) {
		response.setResult(result.packResult());
		MessageEmitterHandler.getInstance().send(messageSource, response.build());
	}
	

}